import {Config} from 'config.js';

class Base {

  constructor(){
    this.baseRequestUrl = Config.url;
  }

  // http请求
  request(params){
    var url = this.baseRequestUrl + params.url
    if(!params.type){
      params.type = 'GET';
    }    
    wx.request({
      url: url,
      header:{
        'Content-Type':'application/json',
        'token':wx.getStorageSync('token')
      },
      method:params.type,
      data:params.data,
      success:function(res){
        var code = res.statusCode.toString();
        var strChar = code.charAt(0);
        if(strChar == '2'){
          params.sCallBack && params.sCallBack(res.data);   
        }else{
          if(code == '401'){
            
          }
          params.eCallBack && params.eCallBack(res.data);
        }
             
      },
      fail:function(err){

      }
    })
  }

  // 获取元素上绑定的值 
  getDataSet(event,key){
    return event.currentTarget.dataset[key];
  }

}
export {Base};